package com.sds.book.springcloud.sentinel.rule;

import com.alibaba.csp.sentinel.init.InitFunc;
import com.alibaba.csp.sentinel.slots.block.RuleConstant;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 01420175
 * @since 2024/3/21
 */
public class FlowRuleInitFunc implements InitFunc {
    @Override
    public void init() throws Exception {
        List<FlowRule> ruleList = new ArrayList<>(2);
        FlowRule rule = new FlowRule();
        rule.setCount(1);
        rule.setRefResource("hello");
        rule.setGrade(RuleConstant.FLOW_GRADE_QPS);
        rule.setLimitApp("default");

        ruleList.add(rule);
        FlowRuleManager.loadRules(ruleList);
    }

}
